<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>31.Number方法扩展</title>
</head>
<body>
<script>
  //很多语言都有这个奇怪的现象
  console.log(0.1+0.2===0.3)//false
  //数字存在一个最小精度，两个数值相差小于这个这个精度，默认相同
  function equals(a, b) {
    return Math.abs(a-b)<Number.EPSILON
  }
  console.log(equals((0.1+0.2),0.3))//true
  console.log(equals(-1,99))//false

  //二进制和八进制
  let b = 0b100
  let o = 0o100
  console.log('二进制100：'+b)
  console.log('八进制100：'+o)
  
  //是否有限
  console.log(Number.isFinite(100/0))//false
  console.log(Number.isFinite(Infinity))//false


  //数值转换
  console.log(Number.parseInt('89opipio'))//89
  console.log(Number.parseInt('sa89pio'))//NAN
  console.log(Number.parseFloat('90.89addaa'))//90.89

  //是否是整数
  console.log(Number.isInteger(9))//true
  console.log(Number.isInteger(9.00))//true
  console.log(Number.isInteger(9.01))//false


  //向下取整
  console.log(Math.trunc(3.1))//3
  console.log(Math.trunc(3.9))//3
  console.log(Math.trunc(3.0))//3

  //判断正负
  console.log(Math.sign(10))//1
  console.log(Math.sign(0))//0
  console.log(Math.sign(-10))//-1
</script>
</body>
</html>